﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Skynet.Office.Media
{
    public partial class MediaView : Form
    {
        public MediaView()
        {
            InitializeComponent();
            this.axWindowsMediaPlayer1.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(axWindowsMediaPlayer1_PlayStateChange);
        }

        void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
        {
            switch (e.newState)
            {
                case  3:
                    this.Text = "playing  " + System.IO.Path.GetFileName(this.openFileDialog1.FileName);
                    break;  
                default:
                    break;
            }
            this.Text = e.newState.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.axWindowsMediaPlayer1.settings.autoStart = true;
                this.axWindowsMediaPlayer1.URL = this.openFileDialog1.FileName;   
            }
        }

        private void MediaView_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.axWindowsMediaPlayer1 != null)
            {
                this.axWindowsMediaPlayer1.Ctlcontrols.stop();
                this.axWindowsMediaPlayer1.Dispose();
            }
        }
    }
}
